package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.WipCompletionDetail;
import com.pureut.storage.dto.SalesReturnDetailDto;
import com.pureut.storage.dto.WipCompletionDetailDto;
import com.pureut.storage.mapper.WipCompletionDetailMapper;
import com.pureut.storage.service.WipCompletionDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 * 完工入库明细实现层
 * Author:C
 * Date:2023/01/29 13:51
 * @DESC
 */
@Service
public class WipCompletionDetailServiceImpl extends ServiceImpl<WipCompletionDetailMapper, WipCompletionDetail> implements WipCompletionDetailService {

    @Resource
    WipCompletionDetailMapper wipCompletionDetailMapper;

    /**
     * 完工入库明细列表
     * @param id
     * @return
     */
    @Override
    public List<WipCompletionDetailDto> getWipCompletionDetail(long id) {

        //获取网型标准缓存字典数据
        List<SysDictData> netArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> netMap = netArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //获取铺网类型标准缓存字典数据
        List<SysDictData> netTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> netTypeMap = netTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<WipCompletionDetailDto> wipCompletionDetailList = wipCompletionDetailMapper.getWipCompletionDetailList(id);
        //完工入库明细状态
        List<SysDictData> statusArray = DictUtils.getDictCache("wip_completion_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (WipCompletionDetailDto entity : wipCompletionDetailList) {
            entity.setMaterialNetDict(netMap.get(entity.getMaterialNet()));
            entity.setMaterialNetTypeDict(netTypeMap.get(entity.getMaterialNetType()));
            entity.setStatusDict(statusMap.get(entity.getStatus()));
        }
        return wipCompletionDetailList;
    }
}
